package com.wn.system.listener;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wn.common.model.bank.dto.BankCardRequestDto;
import com.wn.common.utils.MQConstant;
import com.wn.system.entity.UserCard;
import com.wn.system.entity.UserDetail;
import com.wn.system.service.IUserCardService;
import com.wn.system.service.IUserDetailService;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author yellow Docter
 * @date 2024-09-10
 * @desc 蜗牛创想：www.woniuxy.com
 */
@Component
public class BindCardListener {

//    @Autowired
//    private IUserDetailService userDetailService;
//
//    @Autowired
//    private IUserCardService userCardService;
//
//    /**
//     * MQ消费者 进行消费
//     * @param bankCardRequestDto
//     *  @RabbitListener(queues = MQConstant.SDDFP_QUEUE_BIND) 监听 队列中是否有消息  有消息进行消费
//     *  @Payload    把MQ中的消息 进行 转换 (json-bean对象)
//     */
//    @RabbitListener(queues = MQConstant.SDDFP_QUEUE_BIND)
//    public void handlerMsg(@Payload BankCardRequestDto bankCardRequestDto) {
//
//        ExecutorService executorService = Executors.newFixedThreadPool(4);
//        //1. 根据请求流水号，更新用户表u_user_detail中绑卡状态  CARD_BIND_STATUS
//
////        new Thread(()->{
////
////            userDetailService.update(
////                    Wrappers.lambdaUpdate(UserDetail.class)
////                            .set(UserDetail::getCardBindStatus,1)
////                            .eq(UserDetail::getReqCode, bankCardRequestDto.getReqCode())
////            );
////
////        }).start();
//        executorService.execute(()->{
//                   userDetailService.update(
//                           Wrappers.lambdaUpdate(UserDetail.class)
//                            .set(UserDetail::getCardBindStatus,1)
//                            .eq(UserDetail::getReqCode, bankCardRequestDto.getReqCode())
//            );
//        });
//
//        //2. 根据用户id修改u_user_card绑卡记录表中信息  (BANK_NO,BANK_TITLE,STATUS)
//
//        //查询 userDetail 拿到userId
//        LambdaQueryWrapper<UserDetail> queryWrapper = Wrappers.lambdaQuery(UserDetail.class)
//                .eq(UserDetail::getReqCode, bankCardRequestDto.getReqCode());
//        UserDetail userDetail = userDetailService.getOne(queryWrapper);
//
//        userCardService.update(
//                Wrappers.lambdaUpdate(UserCard.class)
//                        .set(UserCard::getBankNo,bankCardRequestDto.getBankNo())
//                        .set(UserCard::getBankTitle,bankCardRequestDto.getBankTitle())
//                        .set(UserCard::getStatus,1)
//                        .eq(UserCard::getUserId,userDetail.getId())
//        );
//    }

}
